package com.zhengxiang.onlinexamination.component.exception.user;


/**
 *用户信息异常类
 * */
public class UserException extends RuntimeException {
    private static final long serialVersionUID = -7864604160297181941L;

    /** 错误码 */
    protected final ErrorCode errorCode;

    /**
     * 无参默认构造UNSPECIFIED
     */
    public UserException() {
        super(UserErrorCode.UNSPECIFIED.getDescription());
        this.errorCode = UserErrorCode.UNSPECIFIED;
    }

    /**
     * 指定错误码构造通用异常
     *
     * @param errorCode 错误码
     */
    public UserException(final ErrorCode errorCode) {
        super(errorCode.getDescription());
        this.errorCode = errorCode;
    }

    /**
     * 指定详细描述构造通用异常
     *
     * @param detailedMessage 详细描述
     */
    public UserException(final String detailedMessage) {
        super(detailedMessage);
        this.errorCode = UserErrorCode.UNSPECIFIED;
    }

    /**
     * 指定导火索构造通用异常
     *
     * @param t 导火索
     */
    public UserException(final Throwable t) {
        super(t);
        this.errorCode = UserErrorCode.UNSPECIFIED;
    }

    /**
     * 构造通用异常
     *
     * @param errorCode       错误码
     * @param detailedMessage 详细描述
     */
    public UserException(final ErrorCode errorCode, final String detailedMessage) {
        super(detailedMessage);
        this.errorCode = errorCode;
    }

    /**
     * 构造通用异常
     *
     * @param errorCode 错误码
     * @param t         导火索
     */
    public UserException(final ErrorCode errorCode, final Throwable t) {
        super(errorCode.getDescription(), t);
        this.errorCode = errorCode;
    }

    /**
     * 构造通用异常
     *
     * @param detailedMessage 详细描述
     * @param t               导火索
     */
    public UserException(final String detailedMessage, final Throwable t) {
        super(detailedMessage, t);
        this.errorCode = UserErrorCode.UNSPECIFIED;
    }

    /**
     * 构造通用异常
     *
     * @param errorCode       错误码
     * @param detailedMessage 详细描述
     * @param t               导火索
     */
    public UserException(final ErrorCode errorCode, final String detailedMessage, final Throwable t) {
        super(detailedMessage, t);
        this.errorCode = errorCode;
    }

    /**
     * 获取错误码
     *
     * @return
     */
    public int getErrorCode() {
        return errorCode.getCode();
    }
}
